﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class SiteInfo_ShowTypeSite : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        string strPage = Request["page"];
        int page = 1;
        try
        {
            page = int.Parse(strPage);
            if (page < 1)
            {
                page = 1;
            }
        }
        catch (Exception ex)
        {
            page = 1;
        }
        bd(page);
        CMSModel.CMSEntities dal = DAL.DBManager.GetCmsEmtity();
    }
    public int GetPage()
    {
        return AspNetPager1.CurrentPageIndex;
    }

    void bd(int page)
    {
        CMSModel.CMSEntities dal1 = DAL.DBManager.GetCmsEmtity();
        //var c = dal1.SiteType_SiteInfo.AsQueryable();
        var id1 = int.Parse(Server.UrlDecode(Request["stid"]));
        var name = Server.UrlDecode(Request["name"]);

        var tt = from a in dal1.SiteType_SiteInfo
                 from b in dal1.SiteType
                 from d in dal1.SiteInfo
                 where a.sid == d.sid && a.stid == b.stid
                 select new { a.id, a.stid, a.sid, d.SiteUrl, a.EditTime, b.name, d.SiteName };

 
        if (!string.IsNullOrEmpty(name))
        {
            tt = tt.Where(x => x.name.Contains(name));
        }
        //if (!string.IsNullOrEmpty(id1))
        //{
        //    tt = tt.Where(x => x.stid.CompareTo(id1));
        //}
        if (id1!=0)
        {
            tt = tt.Where(x => x.stid.Equals(id1));
        }

        AspNetPager1.RecordCount = tt.Count();
        AspNetPager1.CurrentPageIndex = page;
        tt = tt.OrderBy(x => "id").Skip((page - 1) * AspNetPager1.PageSize).Take(AspNetPager1.PageSize);

        Repeater1.DataSource = tt;
        Repeater1.DataBind();

    }
    protected void AspNetPager1_PageChanged(object sender, EventArgs e)
    {
        bd(AspNetPager1.CurrentPageIndex);
    }
}